package com.miracle.erp.servlet.user;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.miracle.erp.model.User;
import com.miracle.erp.service.IUserService;
import com.miracle.erp.util.ForwardUtil;
import com.miracle.erp.util.ObjectFactory;

@WebServlet("/user/list")
public class UserListServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// 获取所有的用户信息
		// 先创建一个对象调用查询方法 得到数据 再存储到表中
		IUserService userService = ObjectFactory.getUserService();
		List<User> users = userService.list();
		// 请求转发到用户展示页面
		req.setAttribute("users",users);
//		req.getRequestDispatcher("/WEB-INF/jsp/user/list.jsp").forward(req,resp);
		ForwardUtil forward = new ForwardUtil();
		forward.forward(req, resp, "user/list");
	}
			
}